package com.fenxiangtech.mall.manager;

import com.fenxiangtech.mall.dao.OrderDAO;
import com.fenxiangtech.mall.model.Order;
import com.fenxiangtech.mall.model.qc.OrderQC;
import com.fenxiangtech.mall.model.qc.Page;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
public class OrderManager {

    @Autowired
    private OrderDAO orderDAO;

    public List<Order> queryOrder(Order order, Integer pageIndex , Integer pageSize){
        Page page = new Page(pageIndex,pageSize);
        OrderQC qc  = new OrderQC();
        qc.setPage(page);
        BeanUtils.copyProperties(order,qc);
        List<Order> orders = orderDAO.listOrder(qc);
        return orders;
    }

    public Long countOrder(Order order){
        OrderQC qc  = new OrderQC();
        BeanUtils.copyProperties(order,qc);
        Long count = orderDAO.countOrder(qc);
        return count;
    }

    public int saveOrder(Order order){

        if(order.getId()!=null){
            return orderDAO.updateOrder(order);
        }else {
            order.setCreateTime(new Date());
            return orderDAO.insertOrder(order);
        }

    }
    public int deleteOrder(Long id){

        return orderDAO.deleteOrderById(id);

    }



}
